package com.wjc.business.controller.admin;




import com.wjc.business.BusinessApplication;
import com.wjc.server.dto.*;
import com.wjc.server.service.CourseCategoryService;
import com.wjc.server.service.CourseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


@RestController
@RequestMapping("/admin/course")
public class CourseController {

    private static final Logger LOG= LoggerFactory.getLogger(BusinessApplication.class);
    public static final String BUSINESS_NAME = "课程";

    @Resource
    private CourseService courseService;

    @Resource
    private CourseCategoryService courseCategoryService;

    //查询
    @GetMapping("/list")
    public CommonDto list(@Valid  CoursePageDto pageDto){
         courseService.list(pageDto);
//         LOG.info("分页有啥: {}",pageDto);
        CommonDto<PageDto> pageDtoCommonDto = new CommonDto<>();
        pageDtoCommonDto.setContent(pageDto);
        return pageDtoCommonDto;
    }

    //查询课程下所有分类
    @GetMapping("/list-category/{courseId}")
    public CommonDto list(@PathVariable Long courseId){
        List<CourseCategoryDto> courseCategoryDtos = courseCategoryService.listByCourse(courseId);
        CommonDto<List<CourseCategoryDto>> commonDto = new CommonDto<>();
        commonDto.setContent(courseCategoryDtos);
        return commonDto;
    }

    //保存
    @PostMapping("/save")
    public CommonDto list(@Valid @RequestBody CourseDto courseDto){
        CommonDto commonDto=new CommonDto<>();
        courseService.save(courseDto);
        return commonDto;

    }

    //删除
    @DeleteMapping("/delete/{id}")
    public CommonDto delete(@PathVariable Long id){
        CommonDto commonDto=new CommonDto<>();
        courseService.delete(id);
        return commonDto;
    }

    //查询课程下内容
    @GetMapping("/find-content/{id}")
    public CommonDto findContent(@PathVariable Long id){
        CourseContentDto courseContentDto = courseService.findContent(id);
        CommonDto<CourseContentDto> commonDto = new CommonDto<>();
        commonDto.setContent(courseContentDto);
        return commonDto;
    }

    //查询课程下内容
    @PostMapping("/save-content")
    public CommonDto findContent(@RequestBody CourseContentDto courseContentDto){
        courseService.saveContent(courseContentDto);
        CommonDto<CourseContentDto> commonDto = new CommonDto<>();
        commonDto.setContent(courseContentDto);
        return commonDto;
    }

    @PostMapping("/sort")
    public CommonDto sort(@RequestBody SortDto sortDto){
        courseService.sort(sortDto);
        CommonDto<SortDto> commonDto = new CommonDto<>();
        commonDto.setContent(sortDto);
        return commonDto;
    }


}
